﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Beat_em_Up
{
    public class Camera : Microsoft.Xna.Framework.GameComponent
    {
        public Matrix View { get; private set; }
        public Matrix Projection { get; private set; }

        /// <summary>
        /// okjdfsfsf
        /// </summary>
        public Vector3 position;

        /// <summary>
        /// lknsclkns
        /// </summary>
        public Vector3 target;

        /// <summary>
        /// lsljdsn
        /// </summary>
        public Vector3 up;

        /// <summary>
        /// Classe câmera
        /// </summary>
        /// <param name="game">instância do jogo (this)</param>
        /// <param name="position">Vector3 de onde a câmera está</param>
        public Camera(Game game, Vector3 position) :
            this(game, position, Vector3.Zero)
        {
            this.position = position;

            var ratio = (float)Game.Window.ClientBounds.Width /
             (float)Game.Window.ClientBounds.Height;

            View = Matrix.CreateLookAt(position, Vector3.Zero, Vector3.Up);
            Projection = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.PiOver4,
                ratio, 1, 100
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="game"></param>
        /// <param name="position"></param>
        /// <param name="target"></param>
        public Camera(Game game, Vector3 position, Vector3 target) :
            this(game, position, target, Vector3.Up)
        {
            this.position = position;
            this.target = target;

            var ratio = (float)Game.Window.ClientBounds.Width /
              (float)Game.Window.ClientBounds.Height;

            View = Matrix.CreateLookAt(position, target, Vector3.Up);
            Projection = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.PiOver4,
                ratio, 1, 100
                );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="game"></param>
        /// <param name="position"></param>
        /// <param name="target"></param>
        /// <param name="up"></param>
        public Camera(Game game, Vector3 position, Vector3 target, Vector3 up)
            : base(game)
        {
            this.position = position;
            this.target = target;
            this.up = up;

            var ratio = (float)Game.Window.ClientBounds.Width /
                (float)Game.Window.ClientBounds.Height;

            View = Matrix.CreateLookAt(position, target, up);
            Projection = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.PiOver4,
                ratio, 1, 100
                );
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            View = Matrix.CreateLookAt(position, target, up);
            
            base.Update(gameTime);
        }
    }
}
